home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / despereaux-swings.swf / scripts / Box2D / Dynamics / b2World.as < prev   
Encoding:
Text File  |  2011-10-17  |  36.9 KB  |  1,029 lines

  1. package Box2D.Dynamics
  2. {
  3.    import Box2D.Collision.*;
  4.    import Box2D.Collision.Shapes.*;
  5.    import Box2D.Common.*;
  6.    import Box2D.Common.Math.*;
  7.    import Box2D.Dynamics.Contacts.*;
  8.    import Box2D.Dynamics.Joints.*;
  9.    
  10.    public class b2World
  11.    {
  12.       
  13.       private static var s_jointColor:b2Color = new b2Color(0.5,0.8,0.8);
  14.       
  15.       public static var m_continuousPhysics:Boolean;
  16.       
  17.       public static var m_warmStarting:Boolean;
  18.       
  19.       private static var s_coreColor:b2Color = new b2Color(0.9,0.6,0.6);
  20.       
  21.       public static var m_positionCorrection:Boolean;
  22.       
  23.       private static var s_xf:b2XForm = new b2XForm();
  24.        
  25.       
  26.       public var m_inv_dt0:Number;
  27.       
  28.       public var m_boundaryListener:b2BoundaryListener;
  29.       
  30.       public var m_contactList:b2Contact;
  31.       
  32.       public var m_blockAllocator:*;
  33.       
  34.       public var m_contactListener:b2ContactListener;
  35.       
  36.       public var m_allowSleep:Boolean;
  37.       
  38.       public var m_broadPhase:b2BroadPhase;
  39.       
  40.       public var m_destructionListener:b2DestructionListener;
  41.       
  42.       public var m_jointCount:int;
  43.       
  44.       public var m_bodyCount:int;
  45.       
  46.       public var m_lock:Boolean;
  47.       
  48.       public var m_positionIterationCount:int;
  49.       
  50.       public var m_groundBody:b2Body;
  51.       
  52.       public var m_contactCount:int;
  53.       
  54.       public var m_debugDraw:b2DebugDraw;
  55.       
  56.       public var m_contactFilter:b2ContactFilter;
  57.       
  58.       public var m_bodyList:b2Body;
  59.       
  60.       public var m_stackAllocator:*;
  61.       
  62.       public var m_jointList:b2Joint;
  63.       
  64.       public var m_gravity:b2Vec2;
  65.       
  66.       public var m_contactManager:b2ContactManager;
  67.       
  68.       public function b2World(param1:b2AABB, param2:b2Vec2, param3:Boolean)
  69.       {
  70.          var _loc4_:b2BodyDef = null;
  71.          m_contactManager = new b2ContactManager();
  72.          super();
  73.          m_destructionListener = null;
  74.          m_boundaryListener = null;
  75.          m_contactFilter = b2ContactFilter.b2_defaultFilter;
  76.          m_contactListener = null;
  77.          m_debugDraw = null;
  78.          m_bodyList = null;
  79.          m_contactList = null;
  80.          m_jointList = null;
  81.          m_bodyCount = 0;
  82.          m_contactCount = 0;
  83.          m_jointCount = 0;
  84.          m_positionCorrection = true;
  85.          m_warmStarting = true;
  86.          m_continuousPhysics = true;
  87.          m_allowSleep = param3;
  88.          m_gravity = param2;
  89.          m_lock = false;
  90.          m_inv_dt0 = 0;
  91.          m_contactManager.m_world = this;
  92.          m_broadPhase = new b2BroadPhase(param1,m_contactManager);
  93.          _loc4_ = new b2BodyDef();
  94.          m_groundBody = CreateBody(_loc4_);
  95.       }
  96.       
  97.       public function DrawJoint(param1:b2Joint) : void
  98.       {
  99.          var _loc2_:b2Body = null;
  100.          var _loc3_:b2Body = null;
  101.          var _loc4_:b2XForm = null;
  102.          var _loc5_:b2XForm = null;
  103.          var _loc6_:b2Vec2 = null;
  104.          var _loc7_:b2Vec2 = null;
  105.          var _loc8_:b2Vec2 = null;
  106.          var _loc9_:b2Vec2 = null;
  107.          var _loc10_:b2Color = null;
  108.          var _loc11_:b2PulleyJoint = null;
  109.          var _loc12_:b2Vec2 = null;
  110.          var _loc13_:b2Vec2 = null;
  111.          _loc2_ = param1.m_body1;
  112.          _loc3_ = param1.m_body2;
  113.          _loc4_ = _loc2_.m_xf;
  114.          _loc5_ = _loc3_.m_xf;
  115.          _loc6_ = _loc4_.position;
  116.          _loc7_ = _loc5_.position;
  117.          _loc8_ = param1.GetAnchor1();
  118.          _loc9_ = param1.GetAnchor2();
  119.          _loc10_ = s_jointColor;
  120.          switch(param1.m_type)
  121.          {
  122.             case b2Joint.e_distanceJoint:
  123.                m_debugDraw.DrawSegment(_loc8_,_loc9_,_loc10_);
  124.                break;
  125.             case b2Joint.e_pulleyJoint:
  126.                _loc12_ = (_loc11_ = param1 as b2PulleyJoint).GetGroundAnchor1();
  127.                _loc13_ = _loc11_.GetGroundAnchor2();
  128.                m_debugDraw.DrawSegment(_loc12_,_loc8_,_loc10_);
  129.                m_debugDraw.DrawSegment(_loc13_,_loc9_,_loc10_);
  130.                m_debugDraw.DrawSegment(_loc12_,_loc13_,_loc10_);
  131.                break;
  132.             case b2Joint.e_mouseJoint:
  133.                m_debugDraw.DrawSegment(_loc8_,_loc9_,_loc10_);
  134.                break;
  135.             default:
  136.                if(_loc2_ != m_groundBody)
  137.                {
  138.                   m_debugDraw.DrawSegment(_loc6_,_loc8_,_loc10_);
  139.                }
  140.                m_debugDraw.DrawSegment(_loc8_,_loc9_,_loc10_);
  141.                if(_loc3_ != m_groundBody)
  142.                {
  143.                   m_debugDraw.DrawSegment(_loc7_,_loc9_,_loc10_);
  144.                }
  145.          }
  146.       }
  147.       
  148.       public function Refilter(param1:b2Shape) : void
  149.       {
  150.          param1.RefilterProxy(m_broadPhase,param1.m_body.m_xf);
  151.       }
  152.       
  153.       public function SetDebugDraw(param1:b2DebugDraw) : void
  154.       {
  155.          m_debugDraw = param1;
  156.       }
  157.       
  158.       public function SetContinuousPhysics(param1:Boolean) : void
  159.       {
  160.          m_continuousPhysics = param1;
  161.       }
  162.       
  163.       public function GetProxyCount() : int
  164.       {
  165.          return m_broadPhase.m_proxyCount;
  166.       }
  167.       
  168.       public function DrawDebugData() : void
  169.       {
  170.          var _loc1_:uint = 0;
  171.          var _loc2_:int = 0;
  172.          var _loc3_:b2Body = null;
  173.          var _loc4_:b2Shape = null;
  174.          var _loc5_:b2Joint = null;
  175.          var _loc6_:b2BroadPhase = null;
  176.          var _loc7_:b2Vec2 = null;
  177.          var _loc8_:b2Vec2 = null;
  178.          var _loc9_:b2Vec2 = null;
  179.          var _loc10_:b2Color = null;
  180.          var _loc11_:b2XForm = null;
  181.          var _loc12_:b2AABB = null;
  182.          var _loc13_:b2AABB = null;
  183.          var _loc14_:Array = null;
  184.          var _loc15_:* = false;
  185.          var _loc16_:uint = 0;
  186.          var _loc17_:b2Pair = null;
  187.          var _loc18_:b2Proxy = null;
  188.          var _loc19_:b2Proxy = null;
  189.          var _loc20_:b2Vec2 = null;
  190.          var _loc21_:b2Vec2 = null;
  191.          var _loc22_:b2Proxy = null;
  192.          var _loc23_:b2PolygonShape = null;
  193.          var _loc24_:b2OBB = null;
  194.          var _loc25_:b2Vec2 = null;
  195.          var _loc26_:b2Mat22 = null;
  196.          var _loc27_:b2Vec2 = null;
  197.          var _loc28_:Number = NaN;
  198.          if(m_debugDraw == null)
  199.          {
  200.             return;
  201.          }
  202.          m_debugDraw.m_sprite.graphics.clear();
  203.          _loc1_ = m_debugDraw.GetFlags();
  204.          _loc7_ = new b2Vec2();
  205.          _loc8_ = new b2Vec2();
  206.          _loc9_ = new b2Vec2();
  207.          _loc10_ = new b2Color(0,0,0);
  208.          _loc12_ = new b2AABB();
  209.          _loc13_ = new b2AABB();
  210.          _loc14_ = [new b2Vec2(),new b2Vec2(),new b2Vec2(),new b2Vec2()];
  211.          if(_loc1_ & b2DebugDraw.e_shapeBit)
  212.          {
  213.             _loc15_ = (_loc1_ & b2DebugDraw.e_coreShapeBit) == b2DebugDraw.e_coreShapeBit;
  214.             _loc3_ = m_bodyList;
  215.             while(_loc3_)
  216.             {
  217.                _loc11_ = _loc3_.m_xf;
  218.                _loc4_ = _loc3_.GetShapeList();
  219.                while(_loc4_)
  220.                {
  221.                   if(_loc3_.IsStatic())
  222.                   {
  223.                      DrawShape(_loc4_,_loc11_,new b2Color(0.5,0.9,0.5),_loc15_);
  224.                   }
  225.                   else if(_loc3_.IsSleeping())
  226.                   {
  227.                      DrawShape(_loc4_,_loc11_,new b2Color(0.5,0.5,0.9),_loc15_);
  228.                   }
  229.                   else
  230.                   {
  231.                      DrawShape(_loc4_,_loc11_,new b2Color(0.9,0.9,0.9),_loc15_);
  232.                   }
  233.                   _loc4_ = _loc4_.m_next;
  234.                }
  235.                _loc3_ = _loc3_.m_next;
  236.             }
  237.          }
  238.          if(_loc1_ & b2DebugDraw.e_jointBit)
  239.          {
  240.             _loc5_ = m_jointList;
  241.             while(_loc5_)
  242.             {
  243.                DrawJoint(_loc5_);
  244.                _loc5_ = _loc5_.m_next;
  245.             }
  246.          }
  247.          if(_loc1_ & b2DebugDraw.e_pairBit)
  248.          {
  249.             _loc6_ = m_broadPhase;
  250.             _loc7_.Set(1 / _loc6_.m_quantizationFactor.x,1 / _loc6_.m_quantizationFactor.y);
  251.             _loc10_.Set(0.9,0.9,0.3);
  252.             _loc2_ = 0;
  253.             while(_loc2_ < b2Pair.b2_tableCapacity)
  254.             {
  255.                _loc16_ = uint(_loc6_.m_pairManager.m_hashTable[_loc2_]);
  256.                while(_loc16_ != b2Pair.b2_nullPair)
  257.                {
  258.                   _loc17_ = _loc6_.m_pairManager.m_pairs[_loc16_];
  259.                   _loc18_ = _loc6_.m_proxyPool[_loc17_.proxyId1];
  260.                   _loc19_ = _loc6_.m_proxyPool[_loc17_.proxyId2];
  261.                   _loc12_.lowerBound.x = _loc6_.m_worldAABB.lowerBound.x + _loc7_.x * _loc6_.m_bounds[0][_loc18_.lowerBounds[0]].value;
  262.                   _loc12_.lowerBound.y = _loc6_.m_worldAABB.lowerBound.y + _loc7_.y * _loc6_.m_bounds[1][_loc18_.lowerBounds[1]].value;
  263.                   _loc12_.upperBound.x = _loc6_.m_worldAABB.lowerBound.x + _loc7_.x * _loc6_.m_bounds[0][_loc18_.upperBounds[0]].value;
  264.                   _loc12_.upperBound.y = _loc6_.m_worldAABB.lowerBound.y + _loc7_.y * _loc6_.m_bounds[1][_loc18_.upperBounds[1]].value;
  265.                   _loc13_.lowerBound.x = _loc6_.m_worldAABB.lowerBound.x + _loc7_.x * _loc6_.m_bounds[0][_loc19_.lowerBounds[0]].value;
  266.                   _loc13_.lowerBound.y = _loc6_.m_worldAABB.lowerBound.y + _loc7_.y * _loc6_.m_bounds[1][_loc19_.lowerBounds[1]].value;
  267.                   _loc13_.upperBound.x = _loc6_.m_worldAABB.lowerBound.x + _loc7_.x * _loc6_.m_bounds[0][_loc19_.upperBounds[0]].value;
  268.                   _loc13_.upperBound.y = _loc6_.m_worldAABB.lowerBound.y + _loc7_.y * _loc6_.m_bounds[1][_loc19_.upperBounds[1]].value;
  269.                   _loc8_.x = 0.5 * (_loc12_.lowerBound.x + _loc12_.upperBound.x);
  270.                   _loc8_.y = 0.5 * (_loc12_.lowerBound.y + _loc12_.upperBound.y);
  271.                   _loc9_.x = 0.5 * (_loc13_.lowerBound.x + _loc13_.upperBound.x);
  272.                   _loc9_.y = 0.5 * (_loc13_.lowerBound.y + _loc13_.upperBound.y);
  273.                   m_debugDraw.DrawSegment(_loc8_,_loc9_,_loc10_);
  274.                   _loc16_ = _loc17_.next;
  275.                }
  276.                _loc2_++;
  277.             }
  278.          }
  279.          if(_loc1_ & b2DebugDraw.e_aabbBit)
  280.          {
  281.             _loc20_ = (_loc6_ = m_broadPhase).m_worldAABB.lowerBound;
  282.             _loc21_ = _loc6_.m_worldAABB.upperBound;
  283.             _loc7_.Set(1 / _loc6_.m_quantizationFactor.x,1 / _loc6_.m_quantizationFactor.y);
  284.             _loc10_.Set(0.9,0.3,0.9);
  285.             _loc2_ = 0;
  286.             while(_loc2_ < b2Settings.b2_maxProxies)
  287.             {
  288.                if((_loc22_ = _loc6_.m_proxyPool[_loc2_]).IsValid() != false)
  289.                {
  290.                   _loc12_.lowerBound.x = _loc20_.x + _loc7_.x * _loc6_.m_bounds[0][_loc22_.lowerBounds[0]].value;
  291.                   _loc12_.lowerBound.y = _loc20_.y + _loc7_.y * _loc6_.m_bounds[1][_loc22_.lowerBounds[1]].value;
  292.                   _loc12_.upperBound.x = _loc20_.x + _loc7_.x * _loc6_.m_bounds[0][_loc22_.upperBounds[0]].value;
  293.                   _loc12_.upperBound.y = _loc20_.y + _loc7_.y * _loc6_.m_bounds[1][_loc22_.upperBounds[1]].value;
  294.                   _loc14_[0].Set(_loc12_.lowerBound.x,_loc12_.lowerBound.y);
  295.                   _loc14_[1].Set(_loc12_.upperBound.x,_loc12_.lowerBound.y);
  296.                   _loc14_[2].Set(_loc12_.upperBound.x,_loc12_.upperBound.y);
  297.                   _loc14_[3].Set(_loc12_.lowerBound.x,_loc12_.upperBound.y);
  298.                   m_debugDraw.DrawPolygon(_loc14_,4,_loc10_);
  299.                }
  300.                _loc2_++;
  301.             }
  302.             _loc14_[0].Set(_loc20_.x,_loc20_.y);
  303.             _loc14_[1].Set(_loc21_.x,_loc20_.y);
  304.             _loc14_[2].Set(_loc21_.x,_loc21_.y);
  305.             _loc14_[3].Set(_loc20_.x,_loc21_.y);
  306.             m_debugDraw.DrawPolygon(_loc14_,4,new b2Color(0.3,0.9,0.9));
  307.          }
  308.          if(_loc1_ & b2DebugDraw.e_obbBit)
  309.          {
  310.             _loc10_.Set(0.5,0.3,0.5);
  311.             _loc3_ = m_bodyList;
  312.             while(_loc3_)
  313.             {
  314.                _loc11_ = _loc3_.m_xf;
  315.                _loc4_ = _loc3_.GetShapeList();
  316.                while(_loc4_)
  317.                {
  318.                   if(_loc4_.m_type == b2Shape.e_polygonShape)
  319.                   {
  320.                      _loc25_ = (_loc24_ = (_loc23_ = _loc4_ as b2PolygonShape).GetOBB()).extents;
  321.                      _loc14_[0].Set(-_loc25_.x,-_loc25_.y);
  322.                      _loc14_[1].Set(_loc25_.x,-_loc25_.y);
  323.                      _loc14_[2].Set(_loc25_.x,_loc25_.y);
  324.                      _loc14_[3].Set(-_loc25_.x,_loc25_.y);
  325.                      _loc2_ = 0;
  326.                      while(_loc2_ < 4)
  327.                      {
  328.                         _loc26_ = _loc24_.R;
  329.                         _loc27_ = _loc14_[_loc2_];
  330.                         _loc28_ = _loc24_.center.x + (_loc26_.col1.x * _loc27_.x + _loc26_.col2.x * _loc27_.y);
  331.                         _loc14_[_loc2_].y = _loc24_.center.y + (_loc26_.col1.y * _loc27_.x + _loc26_.col2.y * _loc27_.y);
  332.                         _loc14_[_loc2_].x = _loc28_;
  333.                         _loc26_ = _loc11_.R;
  334.                         _loc28_ = _loc11_.position.x + (_loc26_.col1.x * _loc27_.x + _loc26_.col2.x * _loc27_.y);
  335.                         _loc14_[_loc2_].y = _loc11_.position.y + (_loc26_.col1.y * _loc27_.x + _loc26_.col2.y * _loc27_.y);
  336.                         _loc14_[_loc2_].x = _loc28_;
  337.                         _loc2_++;
  338.                      }
  339.                      m_debugDraw.DrawPolygon(_loc14_,4,_loc10_);
  340.                   }
  341.                   _loc4_ = _loc4_.m_next;
  342.                }
  343.                _loc3_ = _loc3_.m_next;
  344.             }
  345.          }
  346.          if(_loc1_ & b2DebugDraw.e_centerOfMassBit)
  347.          {
  348.             _loc3_ = m_bodyList;
  349.             while(_loc3_)
  350.             {
  351.                (_loc11_ = s_xf).R = _loc3_.m_xf.R;
  352.                _loc11_.position = _loc3_.GetWorldCenter();
  353.                m_debugDraw.DrawXForm(_loc11_);
  354.                _loc3_ = _loc3_.m_next;
  355.             }
  356.          }
  357.       }
  358.       
  359.       public function DestroyBody(param1:b2Body) : void
  360.       {
  361.          var _loc2_:b2JointEdge = null;
  362.          var _loc3_:b2Shape = null;
  363.          var _loc4_:b2JointEdge = null;
  364.          var _loc5_:b2Shape = null;
  365.          if(m_lock == true)
  366.          {
  367.             return;
  368.          }
  369.          _loc2_ = param1.m_jointList;
  370.          while(_loc2_)
  371.          {
  372.             _loc4_ = _loc2_;
  373.             _loc2_ = _loc2_.next;
  374.             if(m_destructionListener)
  375.             {
  376.                m_destructionListener.SayGoodbyeJoint(_loc4_.joint);
  377.             }
  378.             DestroyJoint(_loc4_.joint);
  379.          }
  380.          _loc3_ = param1.m_shapeList;
  381.          while(_loc3_)
  382.          {
  383.             _loc5_ = _loc3_;
  384.             _loc3_ = _loc3_.m_next;
  385.             if(m_destructionListener)
  386.             {
  387.                m_destructionListener.SayGoodbyeShape(_loc5_);
  388.             }
  389.             _loc5_.DestroyProxy(m_broadPhase);
  390.             b2Shape.Destroy(_loc5_,m_blockAllocator);
  391.          }
  392.          if(param1.m_prev)
  393.          {
  394.             param1.m_prev.m_next = param1.m_next;
  395.          }
  396.          if(param1.m_next)
  397.          {
  398.             param1.m_next.m_prev = param1.m_prev;
  399.          }
  400.          if(param1 == m_bodyList)
  401.          {
  402.             m_bodyList = param1.m_next;
  403.          }
  404.          --m_bodyCount;
  405.       }
  406.       
  407.       public function SetContactFilter(param1:b2ContactFilter) : void
  408.       {
  409.          m_contactFilter = param1;
  410.       }
  411.       
  412.       public function GetGroundBody() : b2Body
  413.       {
  414.          return m_groundBody;
  415.       }
  416.       
  417.       public function DrawShape(param1:b2Shape, param2:b2XForm, param3:b2Color, param4:Boolean) : void
  418.       {
  419.          var _loc5_:b2Color = null;
  420.          var _loc6_:b2CircleShape = null;
  421.          var _loc7_:b2Vec2 = null;
  422.          var _loc8_:Number = NaN;
  423.          var _loc9_:b2Vec2 = null;
  424.          var _loc10_:int = 0;
  425.          var _loc11_:b2PolygonShape = null;
  426.          var _loc12_:int = 0;
  427.          var _loc13_:Array = null;
  428.          var _loc14_:Array = null;
  429.          var _loc15_:Array = null;
  430.          _loc5_ = s_coreColor;
  431.          switch(param1.m_type)
  432.          {
  433.             case b2Shape.e_circleShape:
  434.                _loc6_ = param1 as b2CircleShape;
  435.                _loc7_ = b2Math.b2MulX(param2,_loc6_.m_localPosition);
  436.                _loc8_ = _loc6_.m_radius;
  437.                _loc9_ = param2.R.col1;
  438.                m_debugDraw.DrawSolidCircle(_loc7_,_loc8_,_loc9_,param3);
  439.                if(param4)
  440.                {
  441.                   m_debugDraw.DrawCircle(_loc7_,_loc8_ - b2Settings.b2_toiSlop,_loc5_);
  442.                }
  443.                break;
  444.             case b2Shape.e_polygonShape:
  445.                _loc12_ = (_loc11_ = param1 as b2PolygonShape).GetVertexCount();
  446.                _loc13_ = _loc11_.GetVertices();
  447.                _loc14_ = new Array(b2Settings.b2_maxPolygonVertices);
  448.                _loc10_ = 0;
  449.                while(_loc10_ < _loc12_)
  450.                {
  451.                   _loc14_[_loc10_] = b2Math.b2MulX(param2,_loc13_[_loc10_]);
  452.                   _loc10_++;
  453.                }
  454.                m_debugDraw.DrawSolidPolygon(_loc14_,_loc12_,param3);
  455.                if(param4)
  456.                {
  457.                   _loc15_ = _loc11_.GetCoreVertices();
  458.                   _loc10_ = 0;
  459.                   while(_loc10_ < _loc12_)
  460.                   {
  461.                      _loc14_[_loc10_] = b2Math.b2MulX(param2,_loc15_[_loc10_]);
  462.                      _loc10_++;
  463.                   }
  464.                   m_debugDraw.DrawPolygon(_loc14_,_loc12_,_loc5_);
  465.                }
  466.          }
  467.       }
  468.       
  469.       public function GetContactCount() : int
  470.       {
  471.          return m_contactCount;
  472.       }
  473.       
  474.       public function Solve(param1:b2TimeStep) : void
  475.       {
  476.          var _loc2_:b2Body = null;
  477.          var _loc3_:b2Island = null;
  478.          var _loc4_:b2Contact = null;
  479.          var _loc5_:b2Joint = null;
  480.          var _loc6_:int = 0;
  481.          var _loc7_:Array = null;
  482.          var _loc8_:b2Body = null;
  483.          var _loc9_:int = 0;
  484.          var _loc10_:int = 0;
  485.          var _loc11_:b2Body = null;
  486.          var _loc12_:b2ContactEdge = null;
  487.          var _loc13_:b2JointEdge = null;
  488.          var _loc14_:Boolean = false;
  489.          m_positionIterationCount = 0;
  490.          _loc3_ = new b2Island(m_bodyCount,m_contactCount,m_jointCount,m_stackAllocator,m_contactListener);
  491.          _loc2_ = m_bodyList;
  492.          while(_loc2_)
  493.          {
  494.             _loc2_.m_flags &= ~b2Body.e_islandFlag;
  495.             _loc2_ = _loc2_.m_next;
  496.          }
  497.          _loc4_ = m_contactList;
  498.          while(_loc4_)
  499.          {
  500.             _loc4_.m_flags &= ~b2Contact.e_islandFlag;
  501.             _loc4_ = _loc4_.m_next;
  502.          }
  503.          _loc5_ = m_jointList;
  504.          while(_loc5_)
  505.          {
  506.             _loc5_.m_islandFlag = false;
  507.             _loc5_ = _loc5_.m_next;
  508.          }
  509.          _loc6_ = m_bodyCount;
  510.          _loc7_ = new Array(_loc6_);
  511.          _loc8_ = m_bodyList;
  512.          while(_loc8_)
  513.          {
  514.             if(!(_loc8_.m_flags & (b2Body.e_islandFlag | b2Body.e_sleepFlag | b2Body.e_frozenFlag)))
  515.             {
  516.                if(!_loc8_.IsStatic())
  517.                {
  518.                   _loc3_.Clear();
  519.                   _loc9_ = 0;
  520.                   var _loc15_:*;
  521.                   _loc7_[_loc15_ = _loc9_++] = _loc8_;
  522.                   _loc8_.m_flags |= b2Body.e_islandFlag;
  523.                   while(_loc9_ > 0)
  524.                   {
  525.                      _loc2_ = _loc7_[--_loc9_];
  526.                      _loc3_.AddBody(_loc2_);
  527.                      _loc2_.m_flags &= ~b2Body.e_sleepFlag;
  528.                      if(!_loc2_.IsStatic())
  529.                      {
  530.                         _loc12_ = _loc2_.m_contactList;
  531.                         while(_loc12_)
  532.                         {
  533.                            if(!(_loc12_.contact.m_flags & (b2Contact.e_islandFlag | b2Contact.e_nonSolidFlag)))
  534.                            {
  535.                               if(_loc12_.contact.m_manifoldCount != 0)
  536.                               {
  537.                                  _loc3_.AddContact(_loc12_.contact);
  538.                                  _loc12_.contact.m_flags |= b2Contact.e_islandFlag;
  539.                                  if(!((_loc11_ = _loc12_.other).m_flags & b2Body.e_islandFlag))
  540.                                  {
  541.                                     var _loc16_:*;
  542.                                     _loc7_[_loc16_ = _loc9_++] = _loc11_;
  543.                                     _loc11_.m_flags |= b2Body.e_islandFlag;
  544.                                  }
  545.                               }
  546.                            }
  547.                            _loc12_ = _loc12_.next;
  548.                         }
  549.                         _loc13_ = _loc2_.m_jointList;
  550.                         while(_loc13_)
  551.                         {
  552.                            if(_loc13_.joint.m_islandFlag != true)
  553.                            {
  554.                               _loc3_.AddJoint(_loc13_.joint);
  555.                               _loc13_.joint.m_islandFlag = true;
  556.                               if(!((_loc11_ = _loc13_.other).m_flags & b2Body.e_islandFlag))
  557.                               {
  558.                                  _loc7_[_loc16_ = _loc9_++] = _loc11_;
  559.                                  _loc11_.m_flags |= b2Body.e_islandFlag;
  560.                               }
  561.                            }
  562.                            _loc13_ = _loc13_.next;
  563.                         }
  564.                      }
  565.                   }
  566.                   _loc3_.Solve(param1,m_gravity,m_positionCorrection,m_allowSleep);
  567.                   if(_loc3_.m_positionIterationCount > m_positionIterationCount)
  568.                   {
  569.                      m_positionIterationCount = _loc3_.m_positionIterationCount;
  570.                   }
  571.                   _loc10_ = 0;
  572.                   while(_loc10_ < _loc3_.m_bodyCount)
  573.                   {
  574.                      _loc2_ = _loc3_.m_bodies[_loc10_];
  575.                      if(_loc2_.IsStatic())
  576.                      {
  577.                         _loc2_.m_flags &= ~b2Body.e_islandFlag;
  578.                      }
  579.                      _loc10_++;
  580.                   }
  581.                }
  582.             }
  583.             _loc8_ = _loc8_.m_next;
  584.          }
  585.          _loc2_ = m_bodyList;
  586.          while(_loc2_)
  587.          {
  588.             if(!(_loc2_.m_flags & (b2Body.e_sleepFlag | b2Body.e_frozenFlag)))
  589.             {
  590.                if(!_loc2_.IsStatic())
  591.                {
  592.                   if((_loc14_ = _loc2_.SynchronizeShapes()) == false && m_boundaryListener != null)
  593.                   {
  594.                      m_boundaryListener.Violation(_loc2_);
  595.                   }
  596.                }
  597.             }
  598.             _loc2_ = _loc2_.m_next;
  599.          }
  600.          m_broadPhase.Commit();
  601.       }
  602.       
  603.       public function Query(param1:b2AABB, param2:Array, param3:int) : int
  604.       {
  605.          var _loc4_:Array = null;
  606.          var _loc5_:int = 0;
  607.          var _loc6_:int = 0;
  608.          _loc4_ = new Array(param3);
  609.          _loc5_ = m_broadPhase.QueryAABB(param1,_loc4_,param3);
  610.          _loc6_ = 0;
  611.          while(_loc6_ < _loc5_)
  612.          {
  613.             param2[_loc6_] = _loc4_[_loc6_];
  614.             _loc6_++;
  615.          }
  616.          return _loc5_;
  617.       }
  618.       
  619.       public function SetGravity(param1:b2Vec2) : void
  620.       {
  621.          m_gravity = param1;
  622.       }
  623.       
  624.       public function SolveTOI(param1:b2TimeStep) : void
  625.       {
  626.          var _loc2_:b2Body = null;
  627.          var _loc3_:b2Shape = null;
  628.          var _loc4_:b2Shape = null;
  629.          var _loc5_:b2Body = null;
  630.          var _loc6_:b2Body = null;
  631.          var _loc7_:b2ContactEdge = null;
  632.          var _loc8_:b2Island = null;
  633.          var _loc9_:int = 0;
  634.          var _loc10_:Array = null;
  635.          var _loc11_:b2Contact = null;
  636.          var _loc12_:b2Contact = null;
  637.          var _loc13_:Number = NaN;
  638.          var _loc14_:b2Body = null;
  639.          var _loc15_:int = 0;
  640.          var _loc16_:b2TimeStep = null;
  641.          var _loc17_:int = 0;
  642.          var _loc18_:Number = NaN;
  643.          var _loc19_:Number = NaN;
  644.          var _loc20_:b2Body = null;
  645.          var _loc21_:Boolean = false;
  646.          _loc8_ = new b2Island(m_bodyCount,b2Settings.b2_maxTOIContactsPerIsland,0,m_stackAllocator,m_contactListener);
  647.          _loc9_ = m_bodyCount;
  648.          _loc10_ = new Array(_loc9_);
  649.          _loc2_ = m_bodyList;
  650.          while(_loc2_)
  651.          {
  652.             _loc2_.m_flags &= ~b2Body.e_islandFlag;
  653.             _loc2_.m_sweep.t0 = 0;
  654.             _loc2_ = _loc2_.m_next;
  655.          }
  656.          _loc11_ = m_contactList;
  657.          while(_loc11_)
  658.          {
  659.             _loc11_.m_flags &= ~(b2Contact.e_toiFlag | b2Contact.e_islandFlag);
  660.             _loc11_ = _loc11_.m_next;
  661.          }
  662.          while(true)
  663.          {
  664.             _loc12_ = null;
  665.             _loc13_ = 1;
  666.             _loc11_ = m_contactList;
  667.             for(; _loc11_; _loc11_ = _loc11_.m_next)
  668.             {
  669.                if(!(_loc11_.m_flags & (b2Contact.e_slowFlag | b2Contact.e_nonSolidFlag)))
  670.                {
  671.                   _loc18_ = 1;
  672.                   if(_loc11_.m_flags & b2Contact.e_toiFlag)
  673.                   {
  674.                      _loc18_ = _loc11_.m_toi;
  675.                   }
  676.                   else
  677.                   {
  678.                      _loc3_ = _loc11_.m_shape1;
  679.                      _loc4_ = _loc11_.m_shape2;
  680.                      _loc5_ = _loc3_.m_body;
  681.                      _loc6_ = _loc4_.m_body;
  682.                      if((_loc5_.IsStatic() || _loc5_.IsSleeping()) && (_loc6_.IsStatic() || _loc6_.IsSleeping()))
  683.                      {
  684.                         continue;
  685.                      }
  686.                      _loc19_ = _loc5_.m_sweep.t0;
  687.                      if(_loc5_.m_sweep.t0 < _loc6_.m_sweep.t0)
  688.                      {
  689.                         _loc19_ = _loc6_.m_sweep.t0;
  690.                         _loc5_.m_sweep.Advance(_loc19_);
  691.                      }
  692.                      else if(_loc6_.m_sweep.t0 < _loc5_.m_sweep.t0)
  693.                      {
  694.                         _loc19_ = _loc5_.m_sweep.t0;
  695.                         _loc6_.m_sweep.Advance(_loc19_);
  696.                      }
  697.                      if((_loc18_ = b2TimeOfImpact.TimeOfImpact(_loc11_.m_shape1,_loc5_.m_sweep,_loc11_.m_shape2,_loc6_.m_sweep)) > 0 && _loc18_ < 1)
  698.                      {
  699.                         if((_loc18_ = (1 - _loc18_) * _loc19_ + _loc18_) > 1)
  700.                         {
  701.                            _loc18_ = 1;
  702.                         }
  703.                      }
  704.                      _loc11_.m_toi = _loc18_;
  705.                      _loc11_.m_flags |= b2Contact.e_toiFlag;
  706.                   }
  707.                   if(Number.MIN_VALUE < _loc18_ && _loc18_ < _loc13_)
  708.                   {
  709.                      _loc12_ = _loc11_;
  710.                      _loc13_ = _loc18_;
  711.                   }
  712.                }
  713.             }
  714.             if(_loc12_ == null || 1 - 100 * Number.MIN_VALUE < _loc13_)
  715.             {
  716.                break;
  717.             }
  718.             _loc3_ = _loc12_.m_shape1;
  719.             _loc4_ = _loc12_.m_shape2;
  720.             _loc5_ = _loc3_.m_body;
  721.             _loc6_ = _loc4_.m_body;
  722.             _loc5_.Advance(_loc13_);
  723.             _loc6_.Advance(_loc13_);
  724.             _loc12_.Update(m_contactListener);
  725.             _loc12_.m_flags &= ~b2Contact.e_toiFlag;
  726.             if(_loc12_.m_manifoldCount != 0)
  727.             {
  728.                if((_loc14_ = _loc5_).IsStatic())
  729.                {
  730.                   _loc14_ = _loc6_;
  731.                }
  732.                _loc8_.Clear();
  733.                _loc15_ = 0;
  734.                var _loc22_:*;
  735.                _loc10_[_loc22_ = _loc15_++] = _loc14_;
  736.                _loc14_.m_flags |= b2Body.e_islandFlag;
  737.                while(_loc15_ > 0)
  738.                {
  739.                   _loc2_ = _loc10_[--_loc15_];
  740.                   _loc8_.AddBody(_loc2_);
  741.                   _loc2_.m_flags &= ~b2Body.e_sleepFlag;
  742.                   if(!_loc2_.IsStatic())
  743.                   {
  744.                      _loc7_ = _loc2_.m_contactList;
  745.                      while(_loc7_)
  746.                      {
  747.                         if(_loc8_.m_contactCount != _loc8_.m_contactCapacity)
  748.                         {
  749.                            if(!(_loc7_.contact.m_flags & (b2Contact.e_islandFlag | b2Contact.e_slowFlag | b2Contact.e_nonSolidFlag)))
  750.                            {
  751.                               if(_loc7_.contact.m_manifoldCount != 0)
  752.                               {
  753.                                  _loc8_.AddContact(_loc7_.contact);
  754.                                  _loc7_.contact.m_flags |= b2Contact.e_islandFlag;
  755.                                  if(!((_loc20_ = _loc7_.other).m_flags & b2Body.e_islandFlag))
  756.                                  {
  757.                                     if(_loc20_.IsStatic() == false)
  758.                                     {
  759.                                        _loc20_.Advance(_loc13_);
  760.                                        _loc20_.WakeUp();
  761.                                     }
  762.                                     var _loc23_:*;
  763.                                     _loc10_[_loc23_ = _loc15_++] = _loc20_;
  764.                                     _loc20_.m_flags |= b2Body.e_islandFlag;
  765.                                  }
  766.                               }
  767.                            }
  768.                         }
  769.                         _loc7_ = _loc7_.next;
  770.                      }
  771.                   }
  772.                }
  773.                (_loc16_ = new b2TimeStep()).dt = (1 - _loc13_) * param1.dt;
  774.                _loc16_.inv_dt = 1 / _loc16_.dt;
  775.                _loc16_.maxIterations = param1.maxIterations;
  776.                _loc8_.SolveTOI(_loc16_);
  777.                _loc17_ = 0;
  778.                while(_loc17_ < _loc8_.m_bodyCount)
  779.                {
  780.                   _loc2_ = _loc8_.m_bodies[_loc17_];
  781.                   _loc2_.m_flags &= ~b2Body.e_islandFlag;
  782.                   if(!(_loc2_.m_flags & (b2Body.e_sleepFlag | b2Body.e_frozenFlag)))
  783.                   {
  784.                      if(!_loc2_.IsStatic())
  785.                      {
  786.                         if((_loc21_ = _loc2_.SynchronizeShapes()) == false && m_boundaryListener != null)
  787.                         {
  788.                            m_boundaryListener.Violation(_loc2_);
  789.                         }
  790.                         _loc7_ = _loc2_.m_contactList;
  791.                         while(_loc7_)
  792.                         {
  793.                            _loc7_.contact.m_flags &= ~b2Contact.e_toiFlag;
  794.                            _loc7_ = _loc7_.next;
  795.                         }
  796.                      }
  797.                   }
  798.                   _loc17_++;
  799.                }
  800.                _loc17_ = 0;
  801.                while(_loc17_ < _loc8_.m_contactCount)
  802.                {
  803.                   _loc11_ = _loc8_.m_contacts[_loc17_];
  804.                   _loc11_.m_flags &= ~(b2Contact.e_toiFlag | b2Contact.e_islandFlag);
  805.                   _loc17_++;
  806.                }
  807.                m_broadPhase.Commit();
  808.             }
  809.          }
  810.       }
  811.       
  812.       public function GetJointList() : b2Joint
  813.       {
  814.          return m_jointList;
  815.       }
  816.       
  817.       public function Validate() : void
  818.       {
  819.          m_broadPhase.Validate();
  820.       }
  821.       
  822.       public function GetPairCount() : int
  823.       {
  824.          return m_broadPhase.m_pairManager.m_pairCount;
  825.       }
  826.       
  827.       public function GetBodyList() : b2Body
  828.       {
  829.          return m_bodyList;
  830.       }
  831.       
  832.       public function SetWarmStarting(param1:Boolean) : void
  833.       {
  834.          m_warmStarting = param1;
  835.       }
  836.       
  837.       public function SetPositionCorrection(param1:Boolean) : void
  838.       {
  839.          m_positionCorrection = param1;
  840.       }
  841.       
  842.       public function CreateJoint(param1:b2JointDef) : b2Joint
  843.       {
  844.          var _loc2_:b2Joint = null;
  845.          var _loc3_:b2Body = null;
  846.          var _loc4_:b2Shape = null;
  847.          _loc2_ = b2Joint.Create(param1,m_blockAllocator);
  848.          _loc2_.m_prev = null;
  849.          _loc2_.m_next = m_jointList;
  850.          if(m_jointList)
  851.          {
  852.             m_jointList.m_prev = _loc2_;
  853.          }
  854.          m_jointList = _loc2_;
  855.          ++m_jointCount;
  856.          _loc2_.m_node1.joint = _loc2_;
  857.          _loc2_.m_node1.other = _loc2_.m_body2;
  858.          _loc2_.m_node1.prev = null;
  859.          _loc2_.m_node1.next = _loc2_.m_body1.m_jointList;
  860.          if(_loc2_.m_body1.m_jointList)
  861.          {
  862.             _loc2_.m_body1.m_jointList.prev = _loc2_.m_node1;
  863.          }
  864.          _loc2_.m_body1.m_jointList = _loc2_.m_node1;
  865.          _loc2_.m_node2.joint = _loc2_;
  866.          _loc2_.m_node2.other = _loc2_.m_body1;
  867.          _loc2_.m_node2.prev = null;
  868.          _loc2_.m_node2.next = _loc2_.m_body2.m_jointList;
  869.          if(_loc2_.m_body2.m_jointList)
  870.          {
  871.             _loc2_.m_body2.m_jointList.prev = _loc2_.m_node2;
  872.          }
  873.          _loc2_.m_body2.m_jointList = _loc2_.m_node2;
  874.          if(param1.collideConnected == false)
  875.          {
  876.             _loc3_ = param1.body1.m_shapeCount < param1.body2.m_shapeCount ? param1.body1 : param1.body2;
  877.             _loc4_ = _loc3_.m_shapeList;
  878.             while(_loc4_)
  879.             {
  880.                _loc4_.RefilterProxy(m_broadPhase,_loc3_.m_xf);
  881.                _loc4_ = _loc4_.m_next;
  882.             }
  883.          }
  884.          return _loc2_;
  885.       }
  886.       
  887.       public function DestroyJoint(param1:b2Joint) : void
  888.       {
  889.          var _loc2_:Boolean = false;
  890.          var _loc3_:b2Body = null;
  891.          var _loc4_:b2Body = null;
  892.          var _loc5_:b2Body = null;
  893.          var _loc6_:b2Shape = null;
  894.          _loc2_ = param1.m_collideConnected;
  895.          if(param1.m_prev)
  896.          {
  897.             param1.m_prev.m_next = param1.m_next;
  898.          }
  899.          if(param1.m_next)
  900.          {
  901.             param1.m_next.m_prev = param1.m_prev;
  902.          }
  903.          if(param1 == m_jointList)
  904.          {
  905.             m_jointList = param1.m_next;
  906.          }
  907.          _loc3_ = param1.m_body1;
  908.          _loc4_ = param1.m_body2;
  909.          _loc3_.WakeUp();
  910.          _loc4_.WakeUp();
  911.          if(param1.m_node1.prev)
  912.          {
  913.             param1.m_node1.prev.next = param1.m_node1.next;
  914.          }
  915.          if(param1.m_node1.next)
  916.          {
  917.             param1.m_node1.next.prev = param1.m_node1.prev;
  918.          }
  919.          if(param1.m_node1 == _loc3_.m_jointList)
  920.          {
  921.             _loc3_.m_jointList = param1.m_node1.next;
  922.          }
  923.          param1.m_node1.prev = null;
  924.          param1.m_node1.next = null;
  925.          if(param1.m_node2.prev)
  926.          {
  927.             param1.m_node2.prev.next = param1.m_node2.next;
  928.          }
  929.          if(param1.m_node2.next)
  930.          {
  931.             param1.m_node2.next.prev = param1.m_node2.prev;
  932.          }
  933.          if(param1.m_node2 == _loc4_.m_jointList)
  934.          {
  935.             _loc4_.m_jointList = param1.m_node2.next;
  936.          }
  937.          param1.m_node2.prev = null;
  938.          param1.m_node2.next = null;
  939.          b2Joint.Destroy(param1,m_blockAllocator);
  940.          --m_jointCount;
  941.          if(_loc2_ == false)
  942.          {
  943.             _loc6_ = (_loc5_ = _loc3_.m_shapeCount < _loc4_.m_shapeCount ? _loc3_ : _loc4_).m_shapeList;
  944.             while(_loc6_)
  945.             {
  946.                _loc6_.RefilterProxy(m_broadPhase,_loc5_.m_xf);
  947.                _loc6_ = _loc6_.m_next;
  948.             }
  949.          }
  950.       }
  951.       
  952.       public function SetContactListener(param1:b2ContactListener) : void
  953.       {
  954.          m_contactListener = param1;
  955.       }
  956.       
  957.       public function CreateBody(param1:b2BodyDef) : b2Body
  958.       {
  959.          var _loc2_:b2Body = null;
  960.          if(m_lock == true)
  961.          {
  962.             return null;
  963.          }
  964.          _loc2_ = new b2Body(param1,this);
  965.          _loc2_.m_prev = null;
  966.          _loc2_.m_next = m_bodyList;
  967.          if(m_bodyList)
  968.          {
  969.             m_bodyList.m_prev = _loc2_;
  970.          }
  971.          m_bodyList = _loc2_;
  972.          ++m_bodyCount;
  973.          return _loc2_;
  974.       }
  975.       
  976.       public function SetBoundaryListener(param1:b2BoundaryListener) : void
  977.       {
  978.          m_boundaryListener = param1;
  979.       }
  980.       
  981.       public function SetDestructionListener(param1:b2DestructionListener) : void
  982.       {
  983.          m_destructionListener = param1;
  984.       }
  985.       
  986.       public function Step(param1:Number, param2:int) : void
  987.       {
  988.          var _loc3_:b2TimeStep = null;
  989.          m_lock = true;
  990.          _loc3_ = new b2TimeStep();
  991.          _loc3_.dt = param1;
  992.          _loc3_.maxIterations = param2;
  993.          if(param1 > 0)
  994.          {
  995.             _loc3_.inv_dt = 1 / param1;
  996.          }
  997.          else
  998.          {
  999.             _loc3_.inv_dt = 0;
  1000.          }
  1001.          _loc3_.dtRatio = m_inv_dt0 * param1;
  1002.          _loc3_.positionCorrection = m_positionCorrection;
  1003.          _loc3_.warmStarting = m_warmStarting;
  1004.          m_contactManager.Collide();
  1005.          if(_loc3_.dt > 0)
  1006.          {
  1007.             Solve(_loc3_);
  1008.          }
  1009.          if(m_continuousPhysics && _loc3_.dt > 0)
  1010.          {
  1011.             SolveTOI(_loc3_);
  1012.          }
  1013.          DrawDebugData();
  1014.          m_inv_dt0 = _loc3_.inv_dt;
  1015.          m_lock = false;
  1016.       }
  1017.       
  1018.       public function GetBodyCount() : int
  1019.       {
  1020.          return m_bodyCount;
  1021.       }
  1022.       
  1023.       public function GetJointCount() : int
  1024.       {
  1025.          return m_jointCount;
  1026.       }
  1027.    }
  1028. }
  1029.